using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDashState : PlayerState
{
    public PlayerDashState(Player _player, PlayerStateMachine _statemachine, string animBoolname) : base(_player, _statemachine, animBoolname)
    {
    }

    public override void Enter()
    {
        base.Enter();
        stateTimer = player.dashDuration;
    }

    public override void Exit()
    {
        base.Exit();
        player.SetVelocity(0, rb.velocity.y);
    }

    public override void Update()
    {
        base.Update();

        if (!player.IsGroundDetected()&&player.IsWallDetected())
        {
            stateMachine.ChangeState(player.wallSlide);
        }

        if (player.IsGroundDetected() && Input.GetKeyDown(KeyCode.Mouse0))
        {
            stateMachine.ChangeState(player.dashAttack);
        }

        player.SetVelocity(player.dashSpeed * player.dashDir, 0);
        if (stateTimer<0)
        {
            if (player.IsGroundDetected()) stateMachine.ChangeState(player.idleState);
            
            if (!player.IsGroundDetected()) stateMachine.ChangeState(player.airState);
        }
    }
}
